﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		teacherId = sessionAdvice.getAutherUserID();
		
		hashCode = event.getArg("Sign");
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");
		
		checked = false;
	
		try {
			
			if ( decrypt(hashCode, teacherId, "PBEWithMD5AndDES", "Hex") eq taskId ) {
				
				checked = true;
				
				targetArgs = structNew();
				structInsert(targetArgs, "TSK", taskId, true);
				structInsert(targetArgs, "TT", taskType, true);
				structInsert(targetArgs, "Sign", encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex"), true);

				/* 载入期末成绩提交任务 */
				
				sql = "	SELECT 
						   	tm.task_id,
						   	tm.term_id,
						   	tm.cid,
						   	tm.cidx,
						   	tm.task_type,
						   	tm.task_prog,
						   	tm.mark_done,
						   	tm.mark_need,
						   	tm.time_start,
						   	tm.time_submit,
						   	tm.time_unlock,
							c.mark_mode,
							c.course_name,
							c.course_code,
							c.course_credit,
							i.institute_short
					  	FROM 
					  	   	t_task_mark tm
						INNER JOIN t_course c ON c.cid = tm.cid
						INNER JOIN t_institute i ON i.institute_id = c.institute_id
					   	WHERE
							tm.task_id = :taskId ";
				
				queryObj = new Query( datasource = application.dnsSlave );
				queryObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
				rs_task = queryObj.execute(sql=sql).getResult();
				
				/*教师信息*/
				sql = "	SELECT 
       						tch.tch_id,
							tch.tch_name
						FROM
							t_teacher tch
						WHERE
							tch.tch_id = :teacherId ";

				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar");
				rs_teacher = queryObj.execute(sql=sql).getResult();

				markMode =rs_task.mark_mode;

				if ( rs_task.task_prog eq "0" or rs_task.task_prog eq "1" or rs_task.task_prog eq "2" or rs_task.task_prog eq "4" ) {
			
					transaction {
						
						/* 第一步 追加学生名单 */
						
						sql = "SELECT sc.scc_id,
								   sc.task_type,
								   sc.st,
								   sc.retaking,
								   sc.stu_id,
								   sc.cid,
								   sc.term_id,
								   cp.prop_id
							 FROM t_student_course sc
								 INNER JOIN t_course c ON c.cid = sc.cid
								 INNER JOIN t_course_prop cp ON cp.prop_id = c.prop_id
							 WHERE sc.task_id = :taskId 
							   		AND 
									SUBSTR(sc.choose_prop, 2, 1) = '1'
							   		AND NOT EXISTS 
									(
										SELECT 
											tmm.scc_id
									  	FROM 
											t_temp_mark tmm
									 	WHERE 
											tmm.stu_id = sc.stu_id
									   		AND 
											tmm.task_id = sc.task_id)
							 ORDER BY sc.stu_id";
						
						queryObj = new Query(datasource = application.dnsMaster);
						
						queryObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
						
						rs_chooserAdd = queryObj.execute(sql = sql).getResult();
						
						if( rs_chooserAdd.recordCount ){
							
							for( a=1; a LTE rs_chooserAdd.recordCount; a++){
								
								sql = "INSERT INTO t_temp_mark
										  (scc_id,
										   stu_id,
										   cid,
										   term_id,
										   prop_id,
										   task_type,
										   task_id,
										   st,
										   retaking,
										   mark_mode,
										   mark_f,
										   mark_note_f,
										   tch_id,
										   mark_u,
										   mark_m, 
										   mark_note_u, 
										   mark_note_m,
										   mark_note )
										 values(
										   :chooserId ,
										   :studentId ,
										   :courseId ,
										   :termId ,
										   :coursePropId ,
										   :taskType ,
										   :taskId ,
										   :studyType ,
										   :retaking ,
										   :markMode ,
										   :markFinal ,
										   :markNoteFinal ,
										   :teacherId,
										   :markUsual, 
										   :markMiddle, 
										   :markNoteUsual, 
										   :markNoteMiddle, 
										   :markNote 
										 )";

								queryObj = new Query(datasource = application.dnsMaster);

								queryObj.addParam(name="chooserId", value=rs_chooserAdd['scc_id'][a], cfsqltype="cf_sql_varchar");
								queryObj.addParam(name="studentId", value=rs_chooserAdd['stu_id'][a], cfsqltype="cf_sql_varchar");
								queryObj.addParam(name="courseId", value=rs_chooserAdd['cid'][a], cfsqltype="cf_sql_varchar");
								queryObj.addParam(name="termId", value=rs_chooserAdd['term_id'][a], cfsqltype="cf_sql_char");
								queryObj.addParam(name="coursePropId", value=rs_chooserAdd['prop_id'][a], cfsqltype="cf_sql_char");
								queryObj.addParam(name="taskType", value=rs_chooserAdd['task_type'][a], cfsqltype="cf_sql_char");
								queryObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
								queryObj.addParam(name="studyType", value=rs_chooserAdd['st'][a], cfsqltype="cf_sql_char");
								queryObj.addParam(name="retaking", value=rs_chooserAdd['retaking'][a], cfsqltype="cf_sql_char");
								queryObj.addParam(name="markMode", value=rs_task.mark_mode, cfsqltype="cf_sql_char");
								queryObj.addParam(name="markFinal", value=-1, cfsqltype="cf_sql_decimal", scale=2);
								queryObj.addParam(name="markNoteFinal", value="1", cfsqltype="cf_sql_char");
								queryObj.addParam(name="teacherId", value=rs_teacher.tch_id, cfsqltype="cf_sql_varchar");
								queryObj.addParam(name="markUsual", value=-1, cfsqltype="cf_sql_decimal", scale=2);
								queryObj.addParam(name="markMiddle", value=-1, cfsqltype="cf_sql_decimal", scale=2);
								queryObj.addParam(name="markNoteUsual", value="1", cfsqltype="cf_sql_char");
								queryObj.addParam(name="markNoteMiddle", value="1", cfsqltype="cf_sql_char");
								queryObj.addParam(name="markNote", value="1", cfsqltype="cf_sql_char");
								
								queryObj.execute(sql = sql);
								
							}
						}
					}
					
					transaction{	
						/* 第二步 删除多余名单 */
						sql = "	DELETE FROM t_temp_mark tm
									WHERE tm.task_id = :taskId 
									AND NOT EXISTS (
										SELECT sc.scc_id
										FROM t_student_course sc
										WHERE sc.task_id = tm.task_id
										   AND sc.stu_id = tm.stu_id
										   AND SUBSTR(sc.choose_prop, 2, 1) = '1')";
						queryObj = new Query(datasource = application.dnsMaster);
						queryObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
						queryObj.execute(sql=sql);
					}
				
					transaction{
						/* 第三步 更新成绩提交数量 */
						
						sql = "	SELECT 
									count(tmm.scc_id) mark_need,
									SUM(
										CASE
											WHEN tmm.mark_note = '1' and tmm.mark_note_u = '1' and tmm.mark_note_m = '1' and tmm.mark_note_f = '1' and tmm.prop_id = '1' and (tmm.mark_u > 0 OR tmm.mark_u = 0) and (tmm.mark_m > 0 OR tmm.mark_m = 0) and (tmm.mark_f > 0 OR tmm.mark_f = 0) then
												1
											WHEN tmm.mark_note = '1' and tmm.mark_note_u = '1' and tmm.mark_note_m = '1' and tmm.mark_note_f = '1' and tmm.prop_id = '2' and (tmm.mark_u > 0 OR tmm.mark_u = 0) and (tmm.mark_f > 0 OR tmm.mark_f = 0) then
												1
											WHEN tmm.mark_mode = '4' AND (tmm.mark_f > 0 or tmm.mark_f = '0') then
												1 
											WHEN tmm.mark_mode = '2' AND (tmm.mark_f > 0 or tmm.mark_f = '0') then
												1 
											WHEN tmm.mark_note > '1' OR tmm.mark_note < '1' then
												1
											ELSE
												0
									   		END
									) mark_done
							  	FROM t_temp_mark tmm
								WHERE tmm.task_id = :taskId ";

						queryObj = new Query(datasource = application.dnsMaster);
						
						queryObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
						
						rs_task_mark = queryObj.execute(sql = sql).getResult();
						
						sql = "	UPDATE t_task_mark t
									SET t.mark_need = :markNeed , 
										t.mark_done = :markDone 
								WHERE t.task_id = :taskId ";
								
						updateObj = new Query(datasource = application.dnsMaster);
						
						updateObj.addParam(name="markNeed", value=rs_task_mark.mark_need, cfsqltype="cf_sql_integer");
						updateObj.addParam(name="markDone", value=rs_task_mark.mark_done, cfsqltype="cf_sql_integer");
						updateObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
						
						updateObj.execute(sql=sql);
				
					}
				
				}

			}
			
		}
		catch (any ecpt) {
		}
		
		/* 判断当前显示课表内容 */
		currentTab = event.getArg("TabID", "labNotice");
		
		/* 成绩提交默认为 百分制 */
		markSubmitEvent = "taskMarkWizardMode0";
		
		/* 设置为两级制 */
		if ( markMode eq "2" ) {
			markSubmitEvent = "taskMarkWizardMode2";
		}
		
		/* 设置为五级制 */
		if ( markMode eq "4" ) {
			markSubmitEvent = "taskMarkWizardMode4";
		}

	</cfscript>
</cfsilent>

<cfif checked >
	
	<div class="UItab">
		<div class="tabLables">
			<span <cfif currentTab eq "labNotice">class="active"</cfif> id="labNotice" tabTarget="Notice">重要事项</span>
		</div>
	</div>
	<script language="javascript" type="text/javascript">
		//<![CDATA[
		<!--
		$(document).ready(function() {

			/* init Tab */
			$("div.tabContent").hide();
			$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
			$("div.tabLables > span").click(function(){
				var $targetID = $(this).attr("tabTarget");
						
				$("div.tabLables span").removeClass("active");
				$(this).addClass("active");
							
				$("div.tabContent").not('[id="' + $targetID + '"]').hide();
				$("div.tabContent#" + $targetID).show();
			});
						
		});
		// -->
		//]]>
	</script>
	
	<div id="Notice" class="tabContent">
		
		<div class="noticeBlock">
			<div class="operation">
				<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('taskMarkDownloadExcel', targetArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载成绩录入名单</span></a>
			</div>
			<h3>课程考核成绩</h3>
			<p>
				<span class="img icon16x16 message"></span>
				请注意, 这里需要提交的是课程考核成绩. 请首先完成试卷批阅, 根据结构评分标准和考试成绩综合评定学生的课程考核成绩.
			</p>
			<hr/>
		</div>
		
		<table class="UIEditable">
			<thead>
				<tr>
					<td>课程</td>
					<td width="50">课序号</td>
					<td width="90">课程号</td>
					<td width="40">学分</td>
					<td width="50">部门</td>
					<td width="60">提交进度</td>
					<td width="60">计分模式</td>
					<td width="60">状态</td>
				</tr>
			</thead>
			<tbody>
				<tr class="editRows">
					<td><cfoutput>#rs_task.course_name#</cfoutput></td>
					<td><span class="numeric"><cfoutput>#rs_task.cidx#</cfoutput></span></td>
					<td><span class="numeric"><cfoutput>#rs_task.course_code#</cfoutput></span></td>
					<td><span class="numeric"><cfoutput>#numberFormat( rs_task.course_credit, '_.__')#</cfoutput></span></td>
					<td><cfoutput>#rs_task.institute_short#</cfoutput></td>
					<td align="center"><span class="numeric"><cfoutput>#rs_task.mark_done#</cfoutput> / <cfoutput>#rs_task.mark_need#</cfoutput></span></td>
					<td><cfoutput>#dictAdvice.getMarkModeName( markMode )#</cfoutput></td>
					<td><cfoutput>#dictAdvice.getTaskMarkStat( rs_task.task_prog )#</cfoutput></td>
				</tr>
			</tbody>
		</table>

		<!--- 根据计分模式, 跳转到成绩提交页面 --->
		<div class="systemNotice">
			<h3><span class="img icon16x16 info"></span>开始录入成绩信息</h3>
			<p>注意: 您需要在学校规定的时间内完成教学任务的成绩提交. </p>
			<p>为了保证您快速, 准确的完成成绩提交工作, 请首先考虑下载成绩提交模版电子表格, 将成绩记录在电子表格以后, 再通过网络提交课程考核成绩.</p>
					
			<form id="formRemove" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL(markSubmitEvent)#</cfoutput>">
				<input type="hidden" name="TSK" value="<cfoutput>#taskId#</cfoutput>" />
				<input type="hidden" name="TT" value="<cfoutput>#taskType#</cfoutput>" />
				<input type="hidden" name="Sign" value="<cfoutput>#encrypt(taskId, teacherId, 'PBEWithMD5AndDES', 'Hex')#</cfoutput>" />
				<div class="lable"><input class="button2" type="submit" value="录入成绩" /></div>
			</form>
		</div>
		
		
	</div>
	
	
</cfif>